home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 14188 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.6 KB

  1. Path: newdelph.cig.mot.com!ferret!leschkes
  2. From: leschkes@ferret.cig.mot.com (Scott Leschke)
  3. Newsgroups: comp.lang.ada,comp.lang.c++
  4. Subject: Re: some questions re. Ada/GNAT from a C++/GCC user
  5. Date: 28 Mar 96 22:49:16 GMT
  6. Organization: Motorola Cellular Infrastructure Group
  7. Message-ID: <leschkes.828053356@ferret>
  8. References: <wnewmanDoxrCp.DKv@netcom.com>
  9. NNTP-Posting-Host: ferret.cig.mot.com
  10.  
  11. wnewman@netcom.com (Bill Newman) writes:
  12.  
  13. >When I make two different instantiations of a generic package with the
  14. >same arguments, I understand the compiler treats them formally as two
  15. >different packages, which is OK with me.  However, I'd appreciate
  16. >knowing the compiler wouldn't actually output two redundant copies of
  17. >the corresponding (identical?) machine code, but instead share the
  18. >code.  I saw somewhere that the compiler is given considerable freedom
  19. >to share one instantiation between several arguments if it thinks it's
  20. >appropriate, which is also OK with me.  However, I haven't seen any
  21. >guarantee that the compiler won't output redundant copies for
  22. >instantiations with identical arguments.  Is there such a guarantee?
  23.  
  24. My first question would be, why do you want redundant instantiations.
  25. Note that Ada separates instantiation of a generic from use of the
  26. resulting package/subunit.  The general rule of thumb to avoid code-bloat
  27. due to duplicate instantiations is to do the instantiation at the library
  28. level and 'with' the resulting package/subunit.
  29.  
  30. >Why doesn't Ada 95 allow declarations to be interspersed with ordinary
  31. >statements as C++ does?  (Or does it?  _Ada as a Second Language_ is a
  32. >big book!)  It seems to me that the C++ approach is a small but
  33. >definite win.  Does it interact very badly somehow with all those
  34. >guarantees on elaboration order?
  35.  
  36. You can use a block statement.  This is different than C++ in the sense
  37. that objects declared within the block are only in existence within the
  38. block and are finalized at the end.  A block can also have its own
  39. exception handlers.  The syntactic form is (from page 500 of the LRM):
  40.  
  41. block statement ::=
  42.   [block_statement_identifier:]
  43.     [declare
  44.        declarative_part]
  45.     begin
  46.        handled_sequence_of_statements
  47.     end [block_identifier];
  48.  
  49. Note that the block identifier and declaration section are optional.
  50.  
  51.  
  52. For example:
  53.  
  54. declare
  55.    Obj : Pkg.SomeType;
  56. begin
  57.    Pkg.Operation (Object => Obj);
  58.    -- Other stuff
  59. exception
  60.    when Pkg.Some_Exception =>
  61.  
  62.       Do_Something;
  63. end;
  64. -- 
  65. Scott Leschke.........................email: leschkes@cig.mot.com
  66. Motorola, Inc............................ph: 847-632-2786
  67. 1501 W Shure Drive......................fax: 847-632-3145
  68. Arlington Heights, IL   60004......mailstop: 1301
  69.